<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"flat"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="ES6语法 (ECMA Script 6)ES基础入门之let、constECMASCript与JavaScript的关系 ES是JS的标准 （ES是对ECMAScript的缩写） JS是ES的实现     1998-06 ES2 发布 2015-06 ES6正式通过 成为国际标准  let、const与块级作用域let与块级作用域 变量声明 var 直接使用">
<meta property="og:type" content="article">
<meta property="og:title" content="前端&#x2F;JavaScript&#x2F;ES6&#x2F;ES6">
<meta property="og:url" content="http://yoursite.com/2020/03/06/%E5%89%8D%E7%AB%AF/JavaScript/ES6/ES6/index.html">
<meta property="og:site_name" content="heweiliang blog">
<meta property="og:description" content="ES6语法 (ECMA Script 6)ES基础入门之let、constECMASCript与JavaScript的关系 ES是JS的标准 （ES是对ECMAScript的缩写） JS是ES的实现     1998-06 ES2 发布 2015-06 ES6正式通过 成为国际标准  let、const与块级作用域let与块级作用域 变量声明 var 直接使用">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-03-06T08:11:25.211Z">
<meta property="article:modified_time" content="2020-06-26T07:26:18.501Z">
<meta property="article:author" content="heweiliang">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/03/06/%E5%89%8D%E7%AB%AF/JavaScript/ES6/ES6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>前端/JavaScript/ES6/ES6 | heweiliang blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="heweiliang blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">heweiliang blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/yourname" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/03/06/%E5%89%8D%E7%AB%AF/JavaScript/ES6/ES6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="heweiliang">
      <meta itemprop="description" content="heweiliang blog">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="heweiliang blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          前端/JavaScript/ES6/ES6<a href="https://github.com/user-name/repo-name/tree/branch-name/subdirectory-name_posts/%E5%89%8D%E7%AB%AF/JavaScript/ES6/ES6.md" class="post-edit-link" title="编辑" rel="noopener" target="_blank"><i class="fa fa-pencil"></i></a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-06 16:11:25" itemprop="dateCreated datePublished" datetime="2020-03-06T16:11:25+08:00">2020-03-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-06-26 15:26:18" itemprop="dateModified" datetime="2020-06-26T15:26:18+08:00">2020-06-26</time>
              </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>8.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>8 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="ES6语法-ECMA-Script-6"><a href="#ES6语法-ECMA-Script-6" class="headerlink" title="ES6语法 (ECMA Script 6)"></a>ES6语法 (ECMA Script 6)</h2><h4 id="ES基础入门之let、const"><a href="#ES基础入门之let、const" class="headerlink" title="ES基础入门之let、const"></a>ES基础入门之let、const</h4><h6 id="ECMASCript与JavaScript的关系"><a href="#ECMASCript与JavaScript的关系" class="headerlink" title="ECMASCript与JavaScript的关系"></a>ECMASCript与JavaScript的关系</h6><ul>
<li><strong>ES是JS的标准 （ES是对ECMAScript的缩写）</strong></li>
<li><strong>JS是ES的实现</strong>    </li>
<li>1998-06 ES2 发布</li>
<li>2015-06 ES6正式通过 成为国际标准</li>
</ul>
<h4 id="let、const与块级作用域"><a href="#let、const与块级作用域" class="headerlink" title="let、const与块级作用域"></a>let、const与块级作用域</h4><p>let与块级作用域</p>
<p>变量声明</p>
<p>var</p>
<p>直接使用</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">window.location.href === location.href</span><br></pre></td></tr></table></figure>

<h6 id="let和var-的主要区别"><a href="#let和var-的主要区别" class="headerlink" title="let和var 的主要区别"></a>let和var 的主要区别</h6><ul>
<li><p>let声明的变量只能在<strong>当前（块级）作用域内有效</strong></p>
</li>
<li><p>let声明的变量不能被重复声明</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">var str = 'abc';</span><br><span class="line">console.log(str);</span><br><span class="line">var str = '';</span><br><span class="line">console.log(str);</span><br><span class="line">//   abc abc</span><br><span class="line"></span><br><span class="line">var str = 'abc';</span><br><span class="line">console.log(str);</span><br><span class="line">var str = 'cdf';</span><br><span class="line">console.log(str);</span><br><span class="line">//   abc cdf</span><br><span class="line"></span><br><span class="line">let num = 10;</span><br><span class="line">let num = 12; 报错</span><br></pre></td></tr></table></figure>
</li>
<li><p>不存在变量提升</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">console.log(num)</span><br><span class="line">var num = 12;</span><br><span class="line">// undefined</span><br><span class="line"></span><br><span class="line">console.log(num)</span><br><span class="line">let num = 12;</span><br><span class="line">// 报错</span><br></pre></td></tr></table></figure>
</li>
<li><p>var 不受块级作用域的影响</p>
</li>
<li><p>暂存死区</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">let num &#x3D; 10;</span><br><span class="line">&#123;</span><br><span class="line">	console.log(num); &#x2F;&#x2F;拿不到num</span><br><span class="line">	let num &#x3D; 20;</span><br><span class="line">&#125;</span><br><span class="line">console.log(num);</span><br><span class="line">&#x2F;&#x2F; 报错</span><br></pre></td></tr></table></figure>



</li>
</ul>
<h6 id="ES之前的作用域"><a href="#ES之前的作用域" class="headerlink" title="ES之前的作用域"></a>ES之前的作用域</h6><ul>
<li>全局作用域 (window)</li>
<li>函数作用域</li>
<li>eval作用域</li>
</ul>
<h6 id="块级作用域"><a href="#块级作用域" class="headerlink" title="块级作用域"></a>块级作用域</h6><p>一对花括号中的区域{…….}</p>
<p>块级作用域可以嵌套</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">// 例子</span><br><span class="line">if()&#123;</span><br><span class="line">&#125;</span><br><span class="line">for()&#123;</span><br><span class="line">&#125;</span><br><span class="line">try&#123;</span><br><span class="line">&#125;catch(err)&#123;</span><br><span class="line">&#125;</span><br><span class="line">while()&#123;</span><br><span class="line">&#125;</span><br><span class="line">//特殊 &#123;&#125; 是一个对象不是块级作用域</span><br><span class="line">var object= &#123;</span><br><span class="line">	a:1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Js 生成10个按钮，每个点击弹出1-10</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">var i &#x3D; 0;</span><br><span class="line">   for (i &#x3D; 1; i &lt;&#x3D; 10; i++) &#123;</span><br><span class="line">       (function (i) &#123;</span><br><span class="line">           var btn &#x3D; document.createElement(&#39;button&#39;);</span><br><span class="line">         &#x2F;&#x2F; createElement(&#39;&#39;) 创建元素</span><br><span class="line">           btn.innerText &#x3D; i;</span><br><span class="line">         &#x2F;&#x2F; 给按钮添加内容             </span><br><span class="line">           btn.onclick &#x3D; function () &#123;</span><br><span class="line">               alert(i);</span><br><span class="line">           &#125;;</span><br><span class="line">           document.body.appendChild(btn);</span><br><span class="line">        &#x2F;&#x2F; appendChild()             </span><br><span class="line">       &#125;)(i);</span><br><span class="line">       &#x2F;&#x2F;(function(i)&#123; &#125;)(i);</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   for (let i &#x3D; 1; i &lt;&#x3D; 10; i++) </span><br><span class="line">           var btn &#x3D; document.createElement(&#39;button&#39;);</span><br><span class="line">         &#x2F;&#x2F; createElement(&#39;&#39;) 创建元素</span><br><span class="line">           btn.innerText &#x3D; i;</span><br><span class="line">         &#x2F;&#x2F; 给按钮添加内容             </span><br><span class="line">           btn.onclick &#x3D; function () &#123;</span><br><span class="line">               alert(i);</span><br><span class="line">           &#125;;</span><br><span class="line">           document.body.appendChild(btn);</span><br><span class="line">        &#x2F;&#x2F; appendChild()             </span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h6 id="const"><a href="#const" class="headerlink" title="const"></a>const</h6><ul>
<li><p>常量-不可改变的量</p>
</li>
<li><p>和声明变量一样，基本只是关键字的区别</p>
</li>
<li><p>常量必须在声明的时候赋值</p>
</li>
<li><p>与letl类似的特性</p>
</li>
<li><p>不能重复声明</p>
</li>
<li><p>不存在提升</p>
</li>
<li><p>只在当前（块级）作用域内有效</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">var v &#x3D; &#39;变量&#39;</span><br><span class="line">const c &#x3D; &#39;常量&#39;</span><br></pre></td></tr></table></figure>

<p>常量不可变？</p>
<ul>
<li><p>一旦声明常量，就不能再改变（引用类型需要冻结）</p>
</li>
<li><p>常量为引用类型的时候 不能保证不改变(可以改变引用类型)</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"> const xiaoming = &#123;</span><br><span class="line">            age: 14,</span><br><span class="line">            name: '小明'</span><br><span class="line">        &#125;;</span><br><span class="line">console.log(xiaoming);</span><br><span class="line">xiaoming.age = 20;  //地址没有改变</span><br><span class="line">console.log(xiaoming);</span><br><span class="line">xiaoming = &#123;&#125;	//地址改变</span><br><span class="line">console.log(xiaoming); //报错</span><br><span class="line"></span><br><span class="line">const  arr = []</span><br><span class="line">arr.push(1);</span><br><span class="line">console.log(arr);</span><br><span class="line">arr = []; //报错</span><br></pre></td></tr></table></figure>

<p>怎么防止常量为引用类型的时候能够被修改的情况;</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Object.freeze(常量名); //冻结常量为引用类型的时候能够被修改</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">   const xiaoming &#x3D; &#123;</span><br><span class="line">              age: 14,</span><br><span class="line">              name: &#39;小明&#39;</span><br><span class="line">          &#125;;</span><br><span class="line">  Object.freeze(xiaoming) &#x2F;&#x2F;不能修改 冻结        </span><br><span class="line">  console.log(xiaoming);</span><br><span class="line">  xiaoming.age &#x3D; 20;  &#x2F;&#x2F;地址没有改变</span><br><span class="line">  console.log(xiaoming);</span><br><span class="line">  xiaoming &#x3D; &#123;&#125;	&#x2F;&#x2F;地址改变</span><br><span class="line">  console.log(xiaoming); &#x2F;&#x2F;报错</span><br><span class="line">  </span><br><span class="line">  const  arr &#x3D; []</span><br><span class="line">  Object.freeze(arr) &#x2F;&#x2F;不能修改 冻结    </span><br><span class="line">arr.push(1);</span><br><span class="line">  console.log(arr);</span><br><span class="line">arr &#x3D; []; &#x2F;&#x2F;报错</span><br></pre></td></tr></table></figure>

<h6 id="es6之前怎么声明常量"><a href="#es6之前怎么声明常量" class="headerlink" title="es6之前怎么声明常量"></a>es6之前怎么声明常量</h6><ol>
<li><p>假装是常量</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">var BASE_COLOR = '#ff0000'</span><br><span class="line">Object.defineProperty()//往一个对象上添加一个属性，同时可以进行描述</span><br><span class="line">var CST = &#123;&#125;</span><br><span class="line">Object.defineProperty(CST,'BASE_NAME',&#123;</span><br><span class="line">	value: '小明',</span><br><span class="line">	writable: false //只读</span><br><span class="line">&#125;);</span><br><span class="line">Object.seal(CST) //不能扩展但能修改(防止对象被扩展)</span><br><span class="line">//第三个参数描述 第二个参数属性名 第一个参数 ：往那个对象上修改添加属性</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">var ST &#x3D; &#123;a :1&#125;</span><br><span class="line">Object.defineProperty(CST,&#39;a&#39;,&#123;</span><br><span class="line">	writable: false &#x2F;&#x2F;只读</span><br><span class="line">&#125;);</span><br><span class="line">Object.seal(CST) &#x2F;&#x2F;不能扩展但能修改(防止对象被扩展),只用Object.freeze(常量名);的一半功能</span><br></pre></td></tr></table></figure>

<p>封装一个</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">1.遍历属性和方法</span><br><span class="line">2.修改遍历到的属性的描述</span><br><span class="line">3.Object.seal()包装</span><br><span class="line"></span><br><span class="line"> Object.defineProperty(Object, 'freezePolyfill', &#123;</span><br><span class="line">            value: function (obj) &#123;</span><br><span class="line">                var i;</span><br><span class="line">                for (i in obj) &#123;</span><br><span class="line">                    if (obj.hasOwnProperty(i)) &#123;</span><br><span class="line">                        Object.defineProperty(obj, i, &#123;</span><br><span class="line">                            writable: false</span><br><span class="line">                        &#125;);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                Object.seal(obj);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        const xiaoming = &#123;</span><br><span class="line">            age: 14,</span><br><span class="line">            name: '小明'</span><br><span class="line">//		obj:&#123;  a:1&#125;</span><br><span class="line">        &#125;;</span><br><span class="line">//		const Arr = []</span><br><span class="line">        Object.freezePolyfill(xiaoming);</span><br></pre></td></tr></table></figure>

<p>//hasOwnProperty()</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">var obj1 &#x3D; &#123;</span><br><span class="line">          a: 1,</span><br><span class="line">          b: 2</span><br><span class="line">      &#125;</span><br><span class="line">      var obj2 &#x3D; Object.create(obj1);</span><br><span class="line">      obj2.c &#x3D; 3;</span><br><span class="line">      obj2.d &#x3D; 4;</span><br><span class="line">      &#x2F;&#x2F; obj2 本身只有c：3 d:4 &#x2F;&#x2F; a:1与b:2不 是他原型上的,不要</span><br><span class="line">      for (let i in obj2) &#123;</span><br><span class="line">          &#x2F;&#x2F; 解决方法 自身</span><br><span class="line">          if (obj2.hasOwnProperty(i)) &#123;</span><br><span class="line">              document.body.innerHTML +&#x3D; (i + &#39;:&#39; + obj2[i] + &#39;&lt;br&gt;&#39;);</span><br><span class="line">          &#125;</span><br><span class="line">      &#125;</span><br></pre></td></tr></table></figure>

</li>
</ol>
</li>
</ul>
<h4 id="ES6变量的解构赋值"><a href="#ES6变量的解构赋值" class="headerlink" title="ES6变量的解构赋值"></a>ES6变量的解构赋值</h4><h6 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h6><p><strong>解构赋值语法是一个Javascript 表达式，这使得可以将值从数组或属性从对象提取到不同的变量中</strong></p>
<h6 id="解构赋值的分类"><a href="#解构赋值的分类" class="headerlink" title="解构赋值的分类"></a>解构赋值的分类</h6><ul>
<li>数组的解构赋值</li>
<li>对象的解析赋值</li>
<li>字符串的解析赋值</li>
<li>数值与布尔值的解构赋值</li>
<li>函数参数的解构赋值</li>
</ul>
<h6 id="数组的解构赋值"><a href="#数组的解构赋值" class="headerlink" title="数组的解构赋值"></a>数组的解构赋值</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">const arr &#x3D; [1,2,3,4];</span><br><span class="line">let [a,b,c,d] &#x3D; arr</span><br><span class="line"></span><br><span class="line">let a &#x3D; arr[0];</span><br></pre></td></tr></table></figure>

<p>更复 杂的匹配规则</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">const arr &#x3D; [&#39;a&#39;,&#39;b&#39;,[&#39;c&#39;,&#39;d&#39;,[&#39;e&#39;,&#39;f&#39;,&#39;g&#39;]]];</span><br><span class="line">const [a,b] &#x3D; arr &#x2F;&#x2F;拿到a、b的值</span><br><span class="line">const [,b] &#x3D; arr; &#x2F;&#x2F; b的值</span><br><span class="line"> const [, ,[,d]] &#x3D; arr;</span><br><span class="line">const [ , , g] &#x3D; [&#39;e&#39;,&#39;f&#39;,&#39;g&#39;]; &#x2F;&#x2F; g的值</span><br><span class="line">const [ , , [ , , g]] &#x3D; [&#39;c&#39; , &#39;d&#39; , [&#39;e&#39;,&#39;f&#39;,&#39;g&#39;]];</span><br><span class="line">const [ , , [ , , [ , , g]]] &#x3D; arr;</span><br><span class="line"> const [,,[,,[,f]]] &#x3D; arr;</span><br><span class="line"> &#x2F;&#x2F;不用逗号前空格,元素后面不用逗号</span><br></pre></td></tr></table></figure>

<p>扩展运算符</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">const arr1 &#x3D; [1,2,3];</span><br><span class="line">const arr2 &#x3D; [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;];</span><br><span class="line">const arr3 &#x3D; [&#39;zz&#39;,1];</span><br><span class="line">&#x2F;&#x2F;const arr4 &#x3D; [arr1,arr2,arr3];</span><br><span class="line">const arr4 &#x3D; [...arr1,...arr2,....arr3];</span><br><span class="line"></span><br><span class="line">const arr &#x3D; [1,2,3,4];</span><br><span class="line">const [a,b,...c] &#x3D; arr; &#x2F;&#x2F;a&#x3D;1 b &#x3D; 2 c &#x3D;[3,4] 还没所有的值</span><br></pre></td></tr></table></figure>

<p>默认值</p>
<p>没有赋值到underfined</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">const arr &#x3D; [1,underfined,underfined];</span><br><span class="line">const [a,b,c,d] &#x3D; arr; &#x2F;&#x2F;d underfined </span><br><span class="line">const [a,b &#x3D; 2,c,d &#x3D; &#39;bbb&#39;] &#x3D; arr; &#x2F;&#x2F;b 2 d &#x3D; bbb 设置默认值 </span><br><span class="line">const arr &#x3D; [1,underfined,null];</span><br><span class="line">const [a,b,c,d] &#x3D; arr; &#x2F;&#x2F;c null</span><br></pre></td></tr></table></figure>

<p>交换变量</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">let a &#x3D; 20;</span><br><span class="line">let b &#x3D; 10;</span><br><span class="line">let temp;</span><br><span class="line">temp &#x3D; a;</span><br><span class="line">a &#x3D; b;</span><br><span class="line">b &#x3D; temp;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;解构赋值</span><br><span class="line">[a,b] &#x3D; [b,a];</span><br></pre></td></tr></table></figure>

<p>接受多个 函数返回值</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">function getUserInfo(id)&#123;</span><br><span class="line">	return[</span><br><span class="line">		true,</span><br><span class="line">		&#123;</span><br><span class="line">		name : '小明'，</span><br><span class="line">		gender:'女'，</span><br><span class="line">		id: id</span><br><span class="line">		&#125;,</span><br><span class="line">		'请求成功'</span><br><span class="line">	];</span><br><span class="line">&#125;;</span><br><span class="line">新方法</span><br><span class="line">const [status,data,msg] = getUserInfo(123);</span><br><span class="line">// true  &#123;name : '小明'，gender:'女'，id: 123&#125; 请求成功</span><br><span class="line">以前的方法</span><br><span class="line">const resData = getUserInfo(123);</span><br><span class="line">let status = resData[0];</span><br></pre></td></tr></table></figure>



<h6 id="对象的解析赋值"><a href="#对象的解析赋值" class="headerlink" title="对象的解析赋值"></a>对象的解析赋值</h6><ul>
<li>对象的结构赋值与数组的结构赋值相似</li>
<li>等号左右两边都为对象结构 -const {a,b} = {a:1,b:2}</li>
<li>左边的{}中为<strong>需要赋值得变量</strong></li>
<li>右边为需要<strong>解构的对象</strong></li>
</ul>
<p>对象的解构赋值的主要用途</p>
<ul>
<li><p>提取对象属性</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">const &#123; name,hody:[hobdy1],hobdy &#125; &#x3D; &#123;</span><br><span class="line">	name:&#39;小红&#39;，</span><br><span class="line">	hobby:[&#39;学习&#39;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>使用对象传入乱序的函数参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;function AJAX(option)&#123;</span><br><span class="line">&#x2F;&#x2F; 	var type &#x3D; option.type || &#39;get&#39;;</span><br><span class="line">&#x2F;&#x2F; 	console.log(option);</span><br><span class="line">&#x2F;&#x2F;&#125;;</span><br><span class="line">function AJAX(&#123;</span><br><span class="line">	url,</span><br><span class="line">	data,</span><br><span class="line">	type &#x3D; &#39;get&#39;</span><br><span class="line">&#125;)&#123;</span><br><span class="line">	console.log(type);</span><br><span class="line">&#125;;</span><br><span class="line">AJAX(&#123;</span><br><span class="line">	url:&#39;&#x2F;getinfo&#39;,</span><br><span class="line">	data:&#123;</span><br><span class="line">		a:1</span><br><span class="line">	&#125;,</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>



</li>
</ul>
<ul>
<li><p>获取多个函数返回值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">function getUserInfo()</span><br><span class="line">&#123;</span><br><span class="line"> 	return &#123;</span><br><span class="line"> 		status:true,</span><br><span class="line"> 		data:&#123;</span><br><span class="line"> 			name:&#39;小红&#39;</span><br><span class="line"> 		&#125;,</span><br><span class="line"> 		msg:&#39;请求成功&#39;</span><br><span class="line"> 	&#125;；</span><br><span class="line">&#125;;</span><br><span class="line">const &#123;status,data,msg&#125; &#x3D; getUserInfo(123)</span><br><span class="line">&#x2F;&#x2F; const &#123;status,data,msg : message&#125; &#x3D; getUserInfo(123)</span><br></pre></td></tr></table></figure>



</li>
</ul>
<p>对象结构赋值的用法</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">const obj = &#123;</span><br><span class="line">    num : '100',</span><br><span class="line">    name : '张三',</span><br><span class="line">        id :[</span><br><span class="line">        &#123;</span><br><span class="line">            a: 1,</span><br><span class="line">            b: 2,</span><br><span class="line">            c: 3</span><br><span class="line">        &#125;, &#123;</span><br><span class="line">            d: 1,</span><br><span class="line">            f: 2,</span><br><span class="line">            g: 3</span><br><span class="line">        &#125;, &#123;</span><br><span class="line">            j: 1,</span><br><span class="line">            k: 2,</span><br><span class="line">            l: 3</span><br><span class="line">        &#125;</span><br><span class="line">        ]</span><br><span class="line">&#125;; // ;</span><br><span class="line">const &#123; num &#125; = obj;</span><br><span class="line">const &#123; name &#125; = obj //不用逗号分隔</span><br><span class="line">// const &#123; num, name &#125; = obj;</span><br><span class="line">const &#123; id: [id1] &#125; = obj; //只能取出id的第一项，不能取出id的值</span><br><span class="line">const &#123;id:[id1,&#123;a&#125;,&#123;a:as&#125;]&#125; = obj </span><br><span class="line">const &#123; id: [id1,&#123;a&#125;] &#125; = obj;</span><br><span class="line">//const &#123; skill &#125; = obj</span><br><span class="line">//const [ id1 ]  = id; 第一项</span><br></pre></td></tr></table></figure>

<p>稍微复杂的解构条件</p>
<p>扩展运算符</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">const obj &#x3D;&#123;</span><br><span class="line">	a:&#39;1&#39;,</span><br><span class="line">	b:&#39;2&#39;,</span><br><span class="line">	c:&#39;3&#39;</span><br><span class="line">&#125;;</span><br><span class="line">const &#123;a,...oth&#125; &#x3D; obj; &#x2F;&#x2F;可以拿到oth &#x3D; b、c </span><br><span class="line"></span><br><span class="line">const obj1 &#x3D; &#123;</span><br><span class="line">	num : &#39;100&#39;,</span><br><span class="line">	...obj,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<p>如何对已经申明了的变量进行对象的解构赋值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">let age;</span><br><span class="line">const obj &#x3D; &#123;</span><br><span class="line">	name: &#39;小明&#39;，</span><br><span class="line">	age:22</span><br><span class="line">&#125;;</span><br><span class="line">&#x2F;&#x2F;两种方法</span><br><span class="line">(&#123; age &#125;) &#x3D; obj;</span><br><span class="line">let &#123; age &#125; &#x3D; obj;</span><br></pre></td></tr></table></figure>



<p>默认值</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">let girlfriend &#x3D; &#123;</span><br><span class="line">	name:&#39;小红&#39;，</span><br><span class="line">	age:22, &#x2F;&#x2F;age:underfined 去默认值</span><br><span class="line">&#125;;</span><br><span class="line">let &#123; name,age &#x3D; 24, hobby &#x3D;[&#39;学习&#39;] &#125; &#x3D; girlfriend</span><br></pre></td></tr></table></figure>





<h6 id="字符串的解析赋值"><a href="#字符串的解析赋值" class="headerlink" title="字符串的解析赋值"></a>字符串的解析赋值</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">const str &#x3D; &quot;Switch is my first game&quot;;</span><br><span class="line">const [ a, b, c] &#x3D; str;</span><br><span class="line">const [ a, b, c,...oth] &#x3D; str; &#x2F;&#x2F;扩展</span><br><span class="line">&#x2F;&#x2F;分解字符串的三种方式</span><br><span class="line">const [...spStr1 ] &#x3D; str;</span><br><span class="line">const spStr2 &#x3D; str.split(&#39;&#39;);</span><br><span class="line">const spStr3 &#x3D; [...str];</span><br></pre></td></tr></table></figure>

<p>提取属性</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">const &#123;length,split&#125; &#x3D; str;</span><br></pre></td></tr></table></figure>



<h6 id="数值与布尔值的解构赋值"><a href="#数值与布尔值的解构赋值" class="headerlink" title="数值与布尔值的解构赋值"></a>数值与布尔值的解构赋值</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const &#123;valueOf&#125; &#x3D; 1;</span><br><span class="line">const &#123;toString:ts &#125; &#x3D; false</span><br></pre></td></tr></table></figure>



<h6 id="函数参数的解构赋值"><a href="#函数参数的解构赋值" class="headerlink" title="函数参数的解构赋值"></a>函数参数的解构赋值</h6><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">function swap ([x,y])&#123;</span><br><span class="line"> 	return [y,x];</span><br><span class="line">&#125;;</span><br><span class="line">let  arr &#x3D; [1,2];</span><br><span class="line">stt &#x3D; swap(arr);</span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Computer</span>(<span class="params">&#123;</span></span></span><br><span class="line"><span class="function"><span class="params">	cpu,</span></span></span><br><span class="line"><span class="function"><span class="params">	memory,</span></span></span><br><span class="line"><span class="function"><span class="params">	software = [<span class="string">'ie6'</span>],</span></span></span><br><span class="line"><span class="function"><span class="params">	OS = <span class="string">'Windows 3.5'</span></span></span></span><br><span class="line"><span class="function"><span class="params">&#125;</span>)</span>&#123;</span><br><span class="line">	<span class="built_in">console</span>.log(CPU);</span><br><span class="line">	<span class="built_in">console</span>.log(memory);</span><br><span class="line">	<span class="built_in">console</span>.log(sofeware);</span><br><span class="line">	<span class="built_in">console</span>.log(OS);</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">new</span> Computer(&#123;</span><br><span class="line">	memory:<span class="string">'128G'</span>,</span><br><span class="line">	cpu:<span class="string">'80'</span>,</span><br><span class="line">	OS:<span class="string">'windows 10'</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h6 id="自定义弹框实例"><a href="#自定义弹框实例" class="headerlink" title="自定义弹框实例"></a>自定义弹框实例</h6><p>匿名函数</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">(<span class="function"><span class="keyword">function</span>(<span class="params">参数<span class="number">1</span>，参数<span class="number">2</span></span>)</span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#125;)(参数<span class="number">1</span>，参数<span class="number">2</span>);</span><br><span class="line"></span><br><span class="line">(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;)();</span><br></pre></td></tr></table></figure>

<ul>
<li><p>全局作用域 (window)</p>
</li>
<li><p>函数作用域</p>
</li>
<li><p>eval作用域</p>
</li>
<li><p>块级作用域</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;声明在全局作用域下，对全局作用域造成了一个污染</span><br><span class="line">const FINGERS &#x3D; 10</span><br><span class="line">const HEAD &#x3D; 1;</span><br><span class="line">function Person()&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">&#x2F;&#x2F;解决方法使用匿名函数</span><br><span class="line">(function(window,doucument)&#123;</span><br><span class="line">    const FINGERS &#x3D; 10</span><br><span class="line">    const HEAD &#x3D; 1;</span><br><span class="line">    function Person()&#123;</span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    window.Person &#x3D; Person; &#x2F;&#x2F;把Person方法暴露在window里</span><br><span class="line">&#125;)(window,doucument); &#x2F;&#x2F;直接把参数传递进来，减轻函数往外搜索参数，提高性能</span><br></pre></td></tr></table></figure>







<h4 id="ES6扩展"><a href="#ES6扩展" class="headerlink" title="ES6扩展"></a>ES6扩展</h4><p>模板字符串</p>
<p>字符串部分</p>
<p>for-of</p>
<p>unicode</p>
<h4 id="ES6-Promise"><a href="#ES6-Promise" class="headerlink" title="ES6 Promise"></a>ES6 Promise</h4><h4 id="ES6-class"><a href="#ES6-class" class="headerlink" title="ES6 class"></a>ES6 class</h4><h4 id="ES实现图片切换特效"><a href="#ES实现图片切换特效" class="headerlink" title="ES实现图片切换特效"></a>ES实现图片切换特效</h4>
    </div>

    
    
    
        <div class="reward-container">
  <div></div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.jpg" alt="heweiliang 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="heweiliang 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/03/05/%E5%89%8D%E7%AB%AF/Node.js/nodejs%E8%A7%86%E9%A2%91/" rel="prev" title="前端/Node.js/nodejs视频">
      <i class="fa fa-chevron-left"></i> 前端/Node.js/nodejs视频
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/03/13/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/V2RAY+WS+TLS%E5%AE%89%E8%A3%85/" rel="next" title="计算机基础/V2RAY+WS+TLS安装">
      计算机基础/V2RAY+WS+TLS安装 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    
  <div class="comments">
    <div id="lv-container" data-id="city" data-uid="MTAyMC81MDY1MC8yNzEzMw=="></div>
  </div>
  

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#ES6语法-ECMA-Script-6"><span class="nav-number">1.</span> <span class="nav-text">ES6语法 (ECMA Script 6)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ES基础入门之let、const"><span class="nav-number">1.0.1.</span> <span class="nav-text">ES基础入门之let、const</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#ECMASCript与JavaScript的关系"><span class="nav-number">1.0.1.0.1.</span> <span class="nav-text">ECMASCript与JavaScript的关系</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#let、const与块级作用域"><span class="nav-number">1.0.2.</span> <span class="nav-text">let、const与块级作用域</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#let和var-的主要区别"><span class="nav-number">1.0.2.0.1.</span> <span class="nav-text">let和var 的主要区别</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#ES之前的作用域"><span class="nav-number">1.0.2.0.2.</span> <span class="nav-text">ES之前的作用域</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#块级作用域"><span class="nav-number">1.0.2.0.3.</span> <span class="nav-text">块级作用域</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#const"><span class="nav-number">1.0.2.0.4.</span> <span class="nav-text">const</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#es6之前怎么声明常量"><span class="nav-number">1.0.2.0.5.</span> <span class="nav-text">es6之前怎么声明常量</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ES6变量的解构赋值"><span class="nav-number">1.0.3.</span> <span class="nav-text">ES6变量的解构赋值</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#介绍"><span class="nav-number">1.0.3.0.1.</span> <span class="nav-text">介绍</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#解构赋值的分类"><span class="nav-number">1.0.3.0.2.</span> <span class="nav-text">解构赋值的分类</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#数组的解构赋值"><span class="nav-number">1.0.3.0.3.</span> <span class="nav-text">数组的解构赋值</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#对象的解析赋值"><span class="nav-number">1.0.3.0.4.</span> <span class="nav-text">对象的解析赋值</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#字符串的解析赋值"><span class="nav-number">1.0.3.0.5.</span> <span class="nav-text">字符串的解析赋值</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#数值与布尔值的解构赋值"><span class="nav-number">1.0.3.0.6.</span> <span class="nav-text">数值与布尔值的解构赋值</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#函数参数的解构赋值"><span class="nav-number">1.0.3.0.7.</span> <span class="nav-text">函数参数的解构赋值</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#自定义弹框实例"><span class="nav-number">1.0.3.0.8.</span> <span class="nav-text">自定义弹框实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ES6扩展"><span class="nav-number">1.0.4.</span> <span class="nav-text">ES6扩展</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ES6-Promise"><span class="nav-number">1.0.5.</span> <span class="nav-text">ES6 Promise</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ES6-class"><span class="nav-number">1.0.6.</span> <span class="nav-text">ES6 class</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#ES实现图片切换特效"><span class="nav-number">1.0.7.</span> <span class="nav-text">ES实现图片切换特效</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="heweiliang"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">heweiliang</p>
  <div class="site-description" itemprop="description">heweiliang blog</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">96</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:yourname@gmail.com" title="E-Mail → mailto:yourname@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://plus.google.com/yourname" title="Google → https:&#x2F;&#x2F;plus.google.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-google"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://stackoverflow.com/yourname" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fa fa-fw fa-stack-overflow"></i></a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title2</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com">Title3</a>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">heweiliang</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">376k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">5:42</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

<script src="/js/bookmark.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/three-waves.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>


  




  
<script src="/js/local-search.js"></script>













  

  

<script>
NexT.utils.loadComments(document.querySelector('#lv-container'), () => {
  window.livereOptions = {
    refer: location.pathname.replace(CONFIG.root, '').replace('index.html', '')
  };
  (function(d, s) {
    var j, e = d.getElementsByTagName(s)[0];
    if (typeof LivereTower === 'function') { return; }
    j = d.createElement(s);
    j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
    j.async = true;
    e.parentNode.insertBefore(j, e);
  })(document, 'script');
});
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/Epsilon2.1.model.json"},"display":{"position":"left","width":300,"height":600},"mobile":{"show":false},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
